# -*- coding: utf-8 -*-
from PyQt5 import QtWidgets
from gui.stability_repeatability_test.vpi_stability_setting import Ui_Dialog
from PyQt5.QtGui import QIcon, QPixmap
from PyQt5.QtCore import pyqtSignal, pyqtSlot
from PyQt5.QtWidgets import QDialog, QMessageBox
from utils.color_util import color
from utils.log_util import loggings as logger


class VpiStabilityDialog(QtWidgets.QDialog, Ui_Dialog):
    dialogSignal = pyqtSignal(object)

    def __init__(self):
        super().__init__()
        self.setupUi(self)
        icon = QIcon()
        icon.addPixmap(
            QPixmap("icons/logo.ico"),
            QIcon.Normal,
            QIcon.Off)
        self.setWindowIcon(icon)
        self.dcp_list = None

    def set_dcp_list(self, dcp_list):
        print("dcp_list", dcp_list)
        self.dcp_list = dcp_list

    @pyqtSlot()
    def on_btnEnsure_clicked(self):
        try:
            scope_start = self.le_scope_start.text()
            scope_stop = self.le_scope_stop.text()
            step = self.le_scope_stop.text()
            test_num = self.cbb_num_para.currentText().strip()
            duration = self.cbb_duration_para.currentText().strip()
            interval = self.cbb_interval.currentText().strip()
            if all([scope_start, scope_stop, step, test_num, duration, interval]):
                self.dialogSignal.emit(
                    {"start": scope_start, "stop": scope_stop, "step": step, "test_num": test_num, "duration": duration,
                     "interval": interval})
                self.close()
            else:
                self.show_notification("提示", "设置的条件不能为空")
        except Exception as e:
            logger.error("on_btnEnsure_clicked," + str(e))

    def show_notification(self, title, content):
        QMessageBox.information(self, title, content, QMessageBox.Yes, QMessageBox.Yes)

    @pyqtSlot()
    def on_btnCancel_clicked(self):
        self.close()
